package delegated_property

//mutableMap代理 可动态变化的map
fun main(args: Array<String>) {
    val m = mutableMapOf<String, Any?>(
            "name" to "olive888",
            "age" to 21
    )
    val user = MutableMapUser(m)
    println("=================================")
    println("${user.name} - ${user.age}")
    println("${m["name"]} - ${m["age"]}")


    //修改map的值 对象的值也相应的修改了
    m["name"] = "olive666"
    m["age"] = 22

    println("=================================")
    println("${user.name} - ${user.age}")
    println("${m["name"]} - ${m["age"]}")

    //修改对象的值 mutableMap
    user.name = "olive999"
    user.age = 23
    println("=================================")
    println("${user.name} - ${user.age}")
    println("${m["name"]} - ${m["age"]}")
}

class MutableMapUser(map: MutableMap<String, Any?>) {
    var name: String by map
    var age: Int by map
}
